import cv2, sys, numpy as np


if __name__ == "__main__":
    #pixelSize = 0.085*0.085
    anzahl =0
    imgray = cv2.imread("confetti.jpg", cv2.CV_LOAD_IMAGE_GRAYSCALE)
    #imgray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    ret2,tresh = cv2.threshold(imgray,230,255,cv2.THRESH_BINARY)
    contours, hierarchy = cv2.findContours(tresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    for contour in contours:
        if cv2.contourArea(contour)> 500:
            anzahl= anzahl +1
    print anzahl
    cv2.drawContours(imgray,contours,-1,(0,255,0),3)

    #print anz
    cv2.namedWindow("simple opencv window",cv2.CV_WINDOW_AUTOSIZE)
    cv2.imshow("simple opencv window",imgray)
    cv2.waitKey(0)
